package io.yizoo.business.controller;

import io.elm.core.entity.sys_role;
import io.yizoo.business.entity.biz_bms_settlement;
import io.yizoo.business.entity.biz_hrm_ei_basic;
import io.elm.core.CoreController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.EnumSet;
import java.util.List;

@RestController
@RequestMapping("/business/bms/settlement")
public class bms_settlementController extends CoreController {

    @Override
    protected void Init() {
        PowerEntity = biz_bms_settlement.class;
        PowerUse = EnumSet.of(Power.IDDelete, Power.IDAny, Power.IDUpsert);
    }

    @PostMapping("/GetData")
    public Object GetData(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .From(biz_bms_settlement.class, "a")
                        .Select("a.*, b.name as sk_person_name")
                        .LeftJoin(biz_hrm_ei_basic.class,"b", "b.emp_code = a.sk_person")
                        .IsWhere("and a.remark like concat('%', #{remark}, '%')", "remark")
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(ret);
    }

    @PostMapping("/GetSingle")
    public Object GetSingle(@RequestBody String jsonStr) {
        Object ret = Ctor.HMapper.GetSingle(biz_bms_settlement.class,
                Ctor.DMaker(jsonStr).Selector
                        .From(biz_bms_settlement.class)
                        .Where("and contract_id = #{code}","code")
                        .Limit("limit 1")
                        .GetFactor());
        return JsonResult(ret);
    }
}
